<?
	include('./link_utility.inc');
	
	//tests
	/*
		this file is just used to test 'link' generation
	
		CURRENT PAGE                       URL ON PAGE
		http://www.example.com         		   --- ./folder/file.php
		http://www.example.com/folder  		   --- ../file.php
		http://www.example.com/folder  		   --- ../folder/file.php
		http://www.example.com/folder 		   --- folder/file.php
		http://www.example.com         		   --- file.php
		http://www.example.com/folder 		   --- file.php
		http://www.example.com         		   --- folder/file.php
		http://www.example.com/folder  	       --- ./file.php
		http://www.example.com/folder 		   --- http://www.example.com
		http://www.example.com/folder 		   --- /file.php
		http://www.example.com/folder/file.php --- ?param=x&q=2
		http://www.example.com/folder/file.php?--- ?param=x
		http://www.example.com/folder		   --- folder/
		http://www.example.com/folder/x.html   --- ./y.html
	*/
	
	$url         = "http://www.example.com";
	$relativeURL = "./folder/file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . linkResolver($url, $relativeURL) . "<br>";
	if(linkResolver($url, $relativeURL) == "http://www.example.com/folder/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder";
	$relativeURL = "../file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . linkResolver($url, $relativeURL) . "<br>";
	if(linkResolver($url, $relativeURL) == "http://www.example.com/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder";
	$relativeURL = "../folder/file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . linkResolver($url, $relativeURL) . "<br>";
	if(linkResolver($url, $relativeURL) == "http://www.example.com/folder/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder";
	$relativeURL = "folder/file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/folder/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com";
	$relativeURL = "file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder";
	$relativeURL = "file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/folder/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com";
	$relativeURL = "folder/file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/folder/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder";
	$relativeURL = "./file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/folder/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder";
	$relativeURL = "http://www.example.com";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder";
	$relativeURL = "/file.php";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/file.php")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder/file.php";
	$relativeURL = "?param=x&q=2";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/folder/file.php?param=x&q=2")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder/file.php?";
	$relativeURL = "?param=x&q=2";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/folder/file.php?param=x&q=2")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder/";
	$relativeURL = "grading/";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/folder/grading/")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder/x.html";
	$relativeURL = "./y.html";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/folder/y.html")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";
	
	$url         = "http://www.example.com/folder/x.html";
	$relativeURL = "../y.html";
	echo "Using $url with relative URL $relativeURL<br>";
	echo "Result: " . @linkResolver($url, $relativeURL) . "<br>";
	if(@linkResolver($url, $relativeURL) == "http://www.example.com/y.html")
		echo "<font color = 'green'>SUCCESS</font><br>";
	else 
		echo "<font color = 'red'>FAILURE</font><br>";
	echo "<br>";


?>